<!-- 基础配置-原材料 -->
<template>
  <div class="app-container" style="background: #f3f6f9;height: 100%;overflow-y: hidden;">
    <el-row style="height: 100%;">
      <el-col :span="5" style="height: 100%;">
        <div class="boxcss">
          <el-form :model="queryParams" ref="queryForm" size="medium" :inline="true">
            <el-form-item prop="type">
              <el-input style="font-size: 12px;" v-model="queryParams.type" prefix-icon="el-icon-search"
                        placeholder="请输入原材料类型" clearable @keyup.enter.native="handleQuery">
                <el-button slot="append" @click="handleQuery">搜索</el-button>
              </el-input>
            </el-form-item>
          </el-form>
          <div class="ulbox">
            <div :class=" isType == index ? 'libox1' : 'libox'" v-for="(item,index) in typeList" :key="index"
                 @click="onType(index)">
              {{item}}
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="5" style="height: 100%;">
        <div class="boxcss">
          <div style="display: flex;align-items: center;">
            <el-form :model="queryParams" ref="queryForm" size="medium" :inline="true">
              <el-form-item prop="type">
                <el-input style="font-size: 12px;" v-model="queryParams.num" placeholder="请输入原材料编号/名称" clearable
                          @keyup.enter.native="handleQuery">
                  <el-button size="mini" slot="append" icon="el-icon-search" @click="handleQuery"></el-button>
                </el-input>
              </el-form-item>
            </el-form>
            <el-button style="margin-left: 5px;" size="small" icon="el-icon-plus" @click="addNum(1)"></el-button>
          </div>
          <div class="ulbox">
            <div :class="isNum == index ? 'libox3' : 'libox2'" v-for="index in 20" :key="index" @click="onNum(index)">
              <div class="topbox">
                <div class="topboxhbox">
                  <i class="el-icon-s-order" style="color: #409EFF;margin-right: 5px;"></i>
                  YLI{{2410310027 + index}}
                </div>
                <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(index)">
                  <i class="el-icon-delete" slot="reference"></i>
                </el-popconfirm>
              </div>
              <div :class="isNum == index ? 'hcss1' : 'hcss'">
                {{typeList[isType]}}MD-{{index}}
              </div>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="14" style="height: 100%;">
        <el-row :gutter="20" style="height: 100%;">
          <el-col :span="24">
            <div class="boxcss">
              <el-collapse v-model="activeName" accordion>
                <el-collapse-item name="1">
                  <template slot="title">
                    <div
                      style="display: flex;align-items: center;justify-content: space-between;width: calc(100% - 15px);padding-right: 15px;">
                      <div class="hbox">
                        <div class="hboxxian"></div>
                        <div class="hboxhcss">
                          基础信息
                        </div>
                      </div>
                      <el-button size="mini" icon="el-icon-edit" @click.stop="onEdit(1)">编辑</el-button>
                    </div>
                  </template>
                  <div class="jculbox">
                    <div class="jclibox">
                      <div class="jclihcss">原材料编号</div>
                      <div class="jclitcss">YLI24103100271</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">原材料名称</div>
                      <div class="jclitcss">{{typeList[isType]}}001</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">原材料类型</div>
                      <div class="jclitcss">{{typeList[isType]}}</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">原材料批次号</div>
                      <div class="jclitcss">PCH1730553018127</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">品牌</div>
                      <div class="jclitcss">xiaomi</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">计量单位</div>
                      <div class="jclitcss">kg</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">制造商</div>
                      <div class="jclitcss">xiaomizhineng</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">产地</div>
                      <div class="jclitcss">上海</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">生产日期</div>
                      <div class="jclitcss">2024-10-21</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">电压等级</div>
                      <div class="jclitcss">16kv</div>
                    </div>
                    <div class="jclibox">
                      <div class="jclihcss">规格型号</div>
                      <div class="jclitcss">型号1730353018127</div>
                    </div>
                    <div class="jclibox" style="width: 100%;height: 115px;">
                      <div class="jclihcss">备注</div>
                      <div class="jclitcss">暂无备注</div>
                    </div>
                  </div>
                </el-collapse-item>
              </el-collapse>
            </div>
          </el-col>
          <el-col :span="24" style="height: calc(55% - 15px);">
            <div class="boxcss martcss" ref="header">
              <div ref="headerTop">
                <div style="display: flex;align-items: center;justify-content: space-between;width: 100%;">
                  <div class="hbox">
                    <div class="hboxxian"></div>
                    <div class="hboxhcss">
                      检验批次
                    </div>
                  </div>
                  <el-button type="primary" size="mini" icon="el-icon-plus" @click="addNum(2)">新增原材料检</el-button>
                </div>
                <el-form style="display: flex;align-items: center;margin: 15px 0;" :model="queryParams" ref="queryForm"
                         size="mini" label-position="right" :inline="true" label-width="88px">
                  <el-form-item style="display: flex;" label="检验批次号" prop="num">
                    <el-input v-model="queryParams.no" placeholder="请输入检验批次号" clearable
                              @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item style="display: flex;" label="检验日期" prop="datetime">
                    <el-date-picker v-model="queryParams.datetime" type="daterange" range-separator="至"
                                    start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item style="display: flex;">
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                  </el-form-item>
                </el-form>
              </div>
              <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"
                        :max-height="tableMaxHeight">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="检验批次号" align="center" :show-overflow-tooltip="true" width="200" prop="num" />
                <el-table-column label="检验日期" align="center" :show-overflow-tooltip="true" width="200"
                                 prop="datatime" />
                <el-table-column label="生产厂检测报告" align="center" :show-overflow-tooltip="true" width="200" prop="name">
                  <template slot-scope="scope">
                    <div style="color: #67C23A;">
                      {{scope.row.name}}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column label="来料检测报告" align="center" :show-overflow-tooltip="true" width="200" prop="name1">
                  <template slot-scope="scope">
                    <div style="color: #67C23A;">
                      {{scope.row.name1}}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" width="200" fixed="right"
                                 class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="onEdit(2)"
                               v-hasPermi="['develop:GoodsFundBack:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)" style="margin-left: 10px;">
                      <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                 v-hasPermi="['develop:GoodsFundBack:remove']">删除</el-button>
                    </el-popconfirm>
                  </template>
                </el-table-column>
              </el-table>
              <div ref="headerBottom">
                <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                            :limit.sync="queryParams.pageSize" @pagination="getList" />
              </div>
            </div>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
    <RawMaterialNumberOrNameForm ref="rawMaterialNumberOrNameForm" @ok="getList" />
    <RawMaterialDetectionForm ref="rawMaterialDetectionForm" @ok="getList" />
  </div>
</template>

<script>
import RawMaterialNumberOrNameForm from '@/views/develop/factory/setUp/module/RawMaterialNumberOrNameForm'
import RawMaterialDetectionForm from '@/views/develop/factory/setUp/module/RawMaterialDetectionForm'
export default {
  name: 'RawMaterialList',
  components: {
    RawMaterialNumberOrNameForm,
    RawMaterialDetectionForm
  },
  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 研发经费表格数据
      dataList: [],
      activeName: '1',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: '',
        num: '',
        no: '',
        datetime: ''
      },
      isType: 0,
      typeList: ['金属杆', '屏蔽料', '绝缘料', '护套料', '外护套', '铝（铝合金）杆', '镀锌钢线', '铝包钢线', '光纤', '铝包钢', '铝合金线', '硬铝线', '纤膏',
        'PE护套料', '半导电硅胶', '绝缘硅胶', '电磁线', '漆包线', '支撑绝缘体', '铁芯（电压）', '扩张套管', '铜外壳', '套管'
      ],
      isNum: 1,
      numList: [],
      tableMaxHeight: 0
    }
  },
  created() {
    this.getList();
    setTimeout(()=>{
      this.tableMaxHeight = this.$refs.header.offsetHeight - this.$refs.headerTop.offsetHeight - 100
    },500)
    window.addEventListener('resize', this.getTableHeight);
  },
  mounted() {
    this.tableMaxHeight = this.$refs.header.offsetHeight - this.$refs.headerTop.offsetHeight
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {
    getTableHeight() {
      this.tableMaxHeight = this.$refs.header.offsetHeight - this.$refs.headerTop.offsetHeight - 100
    },
    //新增原材料编号名称
    addNum(e) {
      if (e == 1) {
        this.$refs.rawMaterialNumberOrNameForm.handleAdd();
      } else {
        this.$refs.rawMaterialDetectionForm.handleAdd();
      }
    },
    //编辑原材料编号名称
    onEdit(e) {
      if (e == 1) {
        var obj = {
          id: 1,
          num: 'YLI24103100271',
          name: '金属杆001',
          type: '金属杆',
          batchNum: 'PCH1730553018127',
          brand: 'xiaomi',
          unit: 'kg',
          manufacturer: 'xiaomizhineng',
          origin: '上海',
          putStorageTime: '2024-10-21',
          voltageLevel: '16kv',
          speModels: '型号1730353018127',
          eipMatDes: '暂无备注'
        }
        this.$refs.rawMaterialNumberOrNameForm.handleUpdate(obj);
      } else {
        var obj = {}
        this.$refs.rawMaterialDetectionForm.handleUpdate(obj);
      }
    },
    //一级筛选
    onType(e) {
      this.isType = e
      this.isNum = 1
      this.getList()
    },
    onNum(e){
      this.isNum = e
      this.getList()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(e) {
      this.getList();
      this.$modal.msgSuccess("删除成功");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 查询原材料列表 */
    getList() {
      this.loading = true;
      setTimeout(() => {
        this.dataList = [{
          num: 'FSJSG81921001',
          datatime: '2024-11-09',
          name: '7.24-7.28.pdf',
          name1: 'GBT 3048-2007 电'
        },
          {
            num: 'FSJSG81921002',
            datatime: '2024-11-03',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG81921003',
            datatime: '2024-11-22',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG81921004',
            datatime: '2024-11-12',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG81921005',
            datatime: '2024-11-01',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG81921006',
            datatime: '2024-11-01',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG81921007',
            datatime: '2024-11-02',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG81921009',
            datatime: '2024-11-02',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG81921201',
            datatime: '2024-12-02',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          },
          {
            num: 'FSJSG11921121',
            datatime: '2024-10-21',
            name: '7.24-7.28.pdf',
            name1: 'GBT 3048-2007 电'
          }
        ];
        this.total = 10;
        this.loading = false;
      }, 1000)
    },
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-form-item--medium,
::v-deep .el-form-item__content {
  width: 100%;
}

::v-deep .el-collapse-item__wrap,
::v-deep .el-collapse,
::v-deep .el-collapse-item__header {
  border: none;
}

::v-deep .el-date-editor--daterange.el-input__inner {
  width: 228px;
}

::v-deep .el-form-item__label {
  font-size: 12px;
  font-weight: 500;
  padding: 0 5px 0 0;
}

::v-deep .el-form-item {
  margin-bottom: 0;
}

.jculbox {
  display: flex;
  flex-wrap: wrap;
  padding: 0 10px;
}

.jclibox {
  display: flex;
  // align-items: center;
  width: 32%;
  margin-top: 15px;
}

.jclihcss {
  font-size: 12px;
  color: #909399;
  margin-right: 10px;
}

.jclitcss {
  font-size: 12px;
  color: #333;
}

.hbox {
  display: flex;
  align-items: center;
}

.hboxhcss {
  font-size: 16px;
  color: #333;
  font-weight: 600;
}

.hboxxian {
  width: 5px;
  height: 18px;
  background: #1890ff;
  margin-right: 5px;
  border-radius: 2px;
}

.boxcss {
  background: #fff;
  padding: 10px;
  border-radius: 5px;
  margin-right: 15px;
  height: 100%;
}

.martcss {
  margin-top: 15px;
}

.ulbox {
  height: calc(100% - 65px);
  overflow-y: scroll;
  margin-top: 15px;
}

.libox {
  color: #333;
  background: #fff;
  border-color: #fff;
  padding: 10px 15px;
  border-radius: 5px;
  font-size: 12px;
}

.libox1 {
  color: #1890ff;
  background: #e8f4ff;
  border-color: #a3d3ff;
  padding: 10px 15px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
}

.libox2 {
  background: #fff;
  border-color: #fff;
  padding: 10px 15px;
  border-radius: 5px;
  border: 1px solid #90939950;
  margin-bottom: 10px;
}

.libox3 {
  background: #e8f4ff;
  border-color: #a3d3ff;
  border: 1px solid #1890ff;
  padding: 10px 15px;
  border-radius: 5px;
  margin-bottom: 10px;
}

.topbox {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.topboxhbox {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #909399;
}

.hcss {
  font-size: 12px;
  color: #333;
}

.hcss1 {
  font-size: 12px;
  font-weight: 500;
  color: #1890ff;
}
</style>
